<?php

class Skjb_Search_Xapian_Enquire
{
    public $_cPtr=null;

    function __construct($databases) {
        $this->_cPtr=new_Enquire($databases);
    }

    function set_query($query,$qlen=0) {
        Enquire_set_query($this->_cPtr,$query,$qlen);
    }

    function get_query() {
        $r=Enquire_get_query($this->_cPtr);
        return is_resource($r) ? new Skjb_Search_Xapian_Query($r) : $r;
    }

    function set_weighting_scheme($weight) {
        Enquire_set_weighting_scheme($this->_cPtr,$weight);
    }

    function set_collapse_key($collapse_key) {
        Enquire_set_collapse_key($this->_cPtr,$collapse_key);
    }

    const ASCENDING = 1;

    const DESCENDING = 0;

    const DONT_CARE = 2;

    function set_docid_order($order) {
        Enquire_set_docid_order($this->_cPtr,$order);
    }

    function set_cutoff($percent_cutoff,$weight_cutoff=0.0) {
        Enquire_set_cutoff($this->_cPtr,$percent_cutoff,$weight_cutoff);
    }

    function set_sort_by_relevance() {
        Enquire_set_sort_by_relevance($this->_cPtr);
    }

    function set_sort_by_value($sort_key,$ascending=true) {
        Enquire_set_sort_by_value($this->_cPtr,$sort_key,$ascending);
    }

    function set_sort_by_value_then_relevance($sort_key,$ascending=true) {
        Enquire_set_sort_by_value_then_relevance($this->_cPtr,$sort_key,$ascending);
    }

    function set_sort_by_relevance_then_value($sort_key,$ascending=true) {
        Enquire_set_sort_by_relevance_then_value($this->_cPtr,$sort_key,$ascending);
    }

    function set_sort_by_key($sorter,$ascending=true) {
        Enquire_set_sort_by_key($this->_cPtr,$sorter,$ascending);
    }

    function set_sort_by_key_then_relevance($sorter,$ascending=true) {
        Enquire_set_sort_by_key_then_relevance($this->_cPtr,$sorter,$ascending);
    }

    function set_sort_by_relevance_then_key($sorter,$ascending=true) {
        Enquire_set_sort_by_relevance_then_key($this->_cPtr,$sorter,$ascending);
    }

    const INCLUDE_QUERY_TERMS = Enquire_INCLUDE_QUERY_TERMS;

    const USE_EXACT_TERMFREQ = Enquire_USE_EXACT_TERMFREQ;

    function get_mset($first,$maxitems,$checkatleast_or_omrset=null,$omrset=null) {
        switch (func_num_args()) {
        case 2: $r=Enquire_get_mset($this->_cPtr,$first,$maxitems); break;
        case 3: $r=Enquire_get_mset($this->_cPtr,$first,$maxitems,$checkatleast_or_omrset); break;
        default: $r=Enquire_get_mset($this->_cPtr,$first,$maxitems,$checkatleast_or_omrset,$omrset);
        }
        return is_resource($r) ? new Skjb_Search_Xapian_MSet($r) : $r;
    }

    function get_eset($maxitems,$omrset,$flags=0,$k=1.0) {
        $r=Enquire_get_eset($this->_cPtr,$maxitems,$omrset,$flags,$k);
        return is_resource($r) ? new Skjb_Search_Xapian_ESet($r) : $r;
    }

    function get_matching_terms_begin($did_or_i) {
        $r=Enquire_get_matching_terms_begin($this->_cPtr,$did_or_i);
        return is_resource($r) ? new Skjb_Search_Xapian_TermIterator($r) : $r;
    }

    function get_matching_terms_end($did_or_i) {
        $r=Enquire_get_matching_terms_end($this->_cPtr,$did_or_i);
        return is_resource($r) ? new Skjb_Search_Xapian_TermIterator($r) : $r;
    }

    function get_matching_terms($hit) {
        return Enquire_get_matching_terms($this->_cPtr,$hit);
    }

    function get_description() {
        return Enquire_get_description($this->_cPtr);
    }
}